<?php
if(!defined('PATH')) exit();
$storeRecordList->load($account->getId());
$count = 0;
?>
<br />
<table border="0" cellpadding="8" cellspacing="1" width="100%">
<tr><td class="head" colspan="5"><b>Bought items</b></td></tr>
<tr><td width="8%"><b>ID</b></td><td width="30%"><b>Item</b></td><td width="30%"><b>Sent to</b></td><td width="31%"><b>Exact date</b></td><td width="1%"><center><b>#</b></center></td></tr>
<?php
if ($storeRecordList->isLoaded()) {
	$count += $storeRecordList->count();
	while($storeRecord = $storeRecordList->next()) {
		$item->load($storeRecord->offer_id);
		if (!$item->isLoaded()) {
			echo '<tr><td>'.$storeRecord->id.'</td><td colspan="2">Sorry, but this offer has been deleted from store.</td><td>'.date($this->config['website']['date_format'], $storeRecord->time).'</td><td><center>'.$storeRecord->status.'</center></td></td>';
			continue;
		}

		if ($storeRecord->status == Model_StoreRecord::STATUS_NOTDELIVERED) {
			$storeRecord->status = '<img src="' . PATH . '/media/images/bullet_red.png" title="Not delivered!" /></img>';
		} else if ($storeRecord->status == Model_StoreRecord::STATUS_DELIVERED) {
			$storeRecord->status = '<img src="' . PATH . '/media/images/bullet_green.png" title="Delivered!" /></img>';
		} else {
			$storeRecord->status = '<img src="' . PATH . '/media/images/bullet_orange.png" title="Error" /></img>';
		}
	
		$player = $this->ots->createObject('Player');
		$player->load($storeRecord->toguid);
		if (!$storeRecord->toguid) {
			$name = 'your account';
		} else {
			$name = '<a href="' . PATH . '/search/check/' . $player->getId() . '/">' . $player->getName() . '</a>';
		}
?>
		<tr><td><?=$storeRecord->id?></td><td><?=$item->name?></td><td><?=$name?></td><td><?=date($this->config['website']['date_format'], $storeRecord->time)?></td><td><center><?=$storeRecord->status?></center></td></tr>
<?php
	}
} else {
?>
	<tr><td colspan="5">Your record is empty.</td></tr>
<?php
}
?>
</table>
<br/>
<?php
$storeRecordList->loadReceived($account->getId(), $account->getId(), Model_Store::TYPE_PREMMY);
$characters = $account->getPlayersList();
foreach ($characters as $character) {
	$storeRecordList->loadReceived($character->getId(), $account->getId(), Model_Store::TYPE_ITEM, true);
}
?>
<table border="0" cellpadding="8" cellspacing="1" width="100%">
<tr><td class="head" colspan="5"><b>Received items</b></td></tr>
<tr><td width="8%"><b>ID</b></td><td width="30%"><b>Item</b></td><td width="30%"><b>From</b></td><td width="31%"><b>Exact date</b></td><td width="1%"><center><b>#</b></center></td></tr>
<?php
if ($storeRecordList->isLoaded()) {
	$count += $storeRecordList->count();
	while($storeRecord = $storeRecordList->next()) {
		$item->load($storeRecord->offer_id);
		if (!$item->isLoaded()) {
			echo '<tr><td>'.$storeRecord->id.'</td><td colspan="2">Sorry, but this offer has been deleted from store.</td><td>'.date($this->config['website']['date_format'], $storeRecord->time).'</td><td><center>'.$storeRecord->status.'</center></td></td>';
			continue;
		}

		if ($storeRecord->status == Model_StoreRecord::STATUS_NOTDELIVERED) {
			$storeRecord->status = '<img src="' . PATH . '/media/images/bullet_red.png" title="Not delivered!" /></img>';
		} else if ($storeRecord->status == Model_StoreRecord::STATUS_DELIVERED) {
			$storeRecord->status = '<img src="' . PATH . '/media/images/bullet_green.png" title="Delivered!" /></img>';
		} else {
			$storeRecord->status = '<img src="' . PATH . '/media/images/bullet_orange.png" title="Error" /></img>';
		}

		$name = $storeRecord->fromname;
?>
		<tr><td><?=$storeRecord->id?></td><td><?=$item->name?></td><td><?=$name?></td><td><?=date($this->config['website']['date_format'], $storeRecord->time)?></td><td><center><?=$storeRecord->status?></center></td></tr>
<?php
	}
} else {
?>
	<tr><td colspan="5">Your record is empty.</td></tr>
<?php
}
?>
</table>
<?php
$temp_output = ob_get_contents();
ob_clean();
if ($count >= 2) {
	$s = 's';
} else {
	$s = '';
}

$this->archez->showMsg('You are now seeing your latest transactions in our store.<ul><li>You have a total of ' . $count . ' record' . $s . ' in our database.</li></ul>', 'information');
echo $temp_output;
?>